Cannot Write To Registry Key HKEY_LOCAL_MACHINE \\SOFTWARE\\  In Windows 7 with Administrator Powered User Using Code
In Windows 7, using visual studio 2008, When i am using code : RegistryKey rk=Registry.LocalMachine.CreateSubKey("Software\\subkey\\subkey"); I am getting error: Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\subkey\subkey' is denied. I am not able to create subkey in localmachine\software\.. through code,when i a administrator powered user. But this code will work when iam woking it from exact Administrator account and will not work from admin powered account. Any idea to solve this issue. Thanks in advance.
February 1st, 2011 1:18am

With UAC you get a filtered token which represents standard user rights, so you can't write to HKEY_LOCAL_MACHINE. You have to add a new manifest to the app: <security> <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> </requestedPrivileges> </security> <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> <application> <!-- UAC supportedOS Options {e2011457-1546-43c5-a5fe-008deee3d3f0} = Vista {35138b9a-5d96-4fbd-8e2d-a2440225f93a} = Windows 7 --> <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/> <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/> </application> </compatibility> Now you get a UAC prompt each time you run the application. When you accept the prompt you get the full admin token for the program and you can set the value. André "A programmer is just a tool which converts caffeine into code" CLIP- Stellvertreter http://www.winvistaside.de/
Free Windows Admin Tool Kit Click here and download it now
February 1st, 2011 9:01am

Thanks for your replay. By implementing above procedure, when i am calling some files in system 32 in user account, the UAC prompt will come and it is working.But when iam trying to create registry subkey through code then i am getting error:Access denied.
February 4th, 2011 6:55am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics